import 'package:flutter/services.dart';
import 'package:lib_service/sdk_manager.dart';

import '../models/share_model.dart';
import '../models/share_object.dart';

class SDKManagerImpl extends SDKManager {
  final MethodChannel _channel = const MethodChannel('sdk-manager');

  SDKManagerImpl();

  @override
  Future<List<ShareModel>?> getShareClasses(
      {required List<String> shareTypes}) async {
    List<Map>? values = await _channel.invokeListMethod<Map>(
      "getShareClasses",
      {
        "shareTypes": shareTypes,
      },
    );

    return values
        ?.map((e) => ShareModel.fromJson(Map<String, dynamic>.from(e)))
        .toList();
  }

  @override
  Future<bool?> shareView({required ShareObject shareObject}) async {
    return _channel.invokeMethod<bool>(
      'shareView',
      shareObject.toJson(),
    );
  }

  @override
  Future<bool?> shareJson({
    required String type,
    required Map<String, dynamic> shareObject,
  }) async {
    return _channel.invokeMethod<bool>('share', {
      'type': type,
      'shareObject': shareObject,
    });
  }

  @override
  Future<bool?> share({
    required String type,
    required ShareObject shareObject,
  }) async {
    return shareJson(type: type, shareObject: shareObject.toJson());
  }
}
